﻿using ST.Library.UI.NodeEditor;
using STNode_A2B.DataType;
using STNode_A2B.STNodeControls;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Reflection.Emit;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace STNode_A2B.STNodes
{
    [STNode("A2B")]
    public class STNode_Generic : STNode
    {
        private STNodeOption m_op_in;
        private STNodeControl_TextBox ctrl_TextBox;
        private STNodeControl_Label ctrl_Label;
        private int _addr = 44;

        [STNodeProperty("Addr", "IIC Address")]
        public String Text
        {
            get
            {
                return _addr.ToString();
            }
            set
            {              
                int temp;
                if (int.TryParse(value, out temp))
                {
                    ctrl_TextBox.EditorText = value;
                    _addr = int.Parse(value);
                    Invalidate();
                }
                
            }
        }
        private string _nodeName = "Generic";
        [STNodeProperty("Title", "Title")]
        public string NodeName
        {
            get { return _nodeName; }
            set
            {
                this._nodeName = value;
                this.Title = this._nodeName;
            }
        }
        protected override void OnCreate()
        {
            base.OnCreate();
            this.Title = "Generic";
            this.TitleColor = Color.FromArgb(200, Color.Goldenrod);
            this.AutoSize = false;
            this.Size = new Size(170, 50);

            m_op_in = this.InputOptions.Add("IIC", typeof(IIC), true);
            
            ctrl_Label = new STNodeControl_Label();
            ctrl_Label.Size = new Size(40, 20);
            ctrl_Label.Location = new Point(50, 3);
            ctrl_Label.ForeColor = Color.White;
            ctrl_Label.EditorText = "Addr";
            this.Controls.Add(ctrl_Label);

            ctrl_TextBox = new STNodeControl_TextBox();
            ctrl_TextBox.IsAddress = true;
            ctrl_TextBox.DisplayRectangle = new Rectangle(90, 0, 60, 20);
            ctrl_TextBox.EditorText = Text;
            this.Controls.Add(ctrl_TextBox);
            
        }
        protected override void OnOwnerChanged()
        {
            base.OnOwnerChanged();
            if(this.Owner != null)
            {
                this.Owner.SetTypeColor(typeof(IIC), Color.DarkCyan);
            }           

        }
    }
}
